//
//  MoreSGSCViewController.m
//  HNJYB
//
//  Created by Mag1cPanda on 16/8/2.
//  Copyright © 2016年 Mag1cPanda. All rights reserved.
//

#import "IDyz.h"
#import "InfoModel.h"
#import "JCAlertView.h"
#import "MoreSGSCGroup.h"
#import "MoreSGSCViewController.h"
#import "ZRRDViewController.h"
#import "ZRRDView.h"
#import "AccidentPlaceView.h"
#import "WSDatePickerView.h"
#import "DJCameraViewController.h"

@interface MoreSGSCViewController ()
<UITextFieldDelegate,
DJCameraViewControllerDelegate>
{
    UIScrollView *scroll;
    MoreSGSCGroup *partyAGroup;
    MoreSGSCGroup *partyBGroup;
    JCAlertView *jcAlert;
    
    NSString *jfcarType;
    NSString *jfname;
    NSString *jfcarno;
    NSString *jfphoneNum;
    NSString *jfdriveNum;
    NSString *jfframeno;
    NSString *jfbdhNum;
    
    NSString *yfcarType;
    NSString *yfname;
    NSString *yfcarno;
    NSString *yfphoneNum;
    NSString *yfdriveNum;
    NSString *yfframeno;
    NSString *yfbdhNum;
    
    AccidentPlaceView *sgdd;
    ZRRDView *sgsj;
}
@end

@implementation MoreSGSCViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"事故上传";
    
    scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64)];
    [self.view addSubview:scroll];
    
    UILabel *topLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, ScreenWidth-20, 40)];
    topLab.font = [UIFont systemFontOfSize:16];
    topLab.textColor = [UIColor lightGrayColor];
    topLab.numberOfLines = 0;
    topLab.textAlignment = NSTextAlignmentCenter;
    topLab.text = @"请输入双方车牌号和联系方式，便于事故处理";
    [scroll addSubview:topLab];
    
    UIColor *backColor = RGB(234, 234, 234);
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, topLab.maxY+10, ScreenWidth, 150)];
    backView.backgroundColor = backColor;
    [scroll addSubview:backView];
    
    sgsj = [[ZRRDView alloc] initWithFrame:CGRectMake(10, 10, ScreenWidth-20, 50)];
    sgsj.titleLab.text = @"事故时间:";
    sgsj.titleLab.textColor = [UIColor redColor];
    sgsj.contentField.delegate = self;
    sgsj.contentField.placeholder = @"请选择时间";
    sgsj.contentField.enabled = false;
    sgsj.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectTime)];
    [sgsj addGestureRecognizer:tap];
    [backView addSubview:sgsj];
    
    sgdd = [[AccidentPlaceView alloc] initWithFrame:CGRectMake(10, sgsj.maxY+10, ScreenWidth-20, 70)];
    sgdd.contentView.x = sgdd.contentView.x - 20;
    [backView addSubview:sgdd];
    
    //交警账号
    if (UserType == TrafficPolice)
    {
        sgdd.contentView.userInteractionEnabled = YES;
    }
    
    //协警账号
    else
    {
        sgdd.contentView.userInteractionEnabled = NO;
    }
    
    partyAGroup = [[MoreSGSCGroup alloc] initWithFrame:CGRectMake(0, backView.maxY+10, ScreenWidth, 585) groupId:@"partyAGroup"];
    partyAGroup.backgroundColor = backColor;
    partyAGroup.title = @"甲方信息";
    partyAGroup.cphView.field.delegate = self;
    partyAGroup.jszView.field.delegate = self;
    partyAGroup.cjhView.field.delegate = self;
    partyAGroup.lxdhView.field.keyboardType = UIKeyboardTypePhonePad;
    //给获取按钮添加点击事件
    [partyAGroup.codeBtn addTarget:self action:@selector(getBdhCode:) forControlEvents:1<<6];
    [partyAGroup.xmBtn addTarget:self action:@selector(retakePhoto:) forControlEvents:1<<6];
    [partyAGroup.cphBtn addTarget:self action:@selector(retakePhoto:) forControlEvents:1<<6];
    [scroll addSubview:partyAGroup];
    
    partyBGroup = [[MoreSGSCGroup alloc] initWithFrame:CGRectMake(0, partyAGroup.maxY+10, ScreenWidth, 585) groupId:@"partyBGroup"];
    partyBGroup.backgroundColor = backColor;
    partyBGroup.title = @"乙方信息";
    partyBGroup.cphView.field.delegate = self;
    partyBGroup.jszView.field.delegate = self;
    partyBGroup.cjhView.field.delegate = self;
    partyBGroup.lxdhView.field.keyboardType = UIKeyboardTypePhonePad;
    //给获取按钮添加点击事件
    [partyBGroup.codeBtn addTarget:self action:@selector(getBdhCode:) forControlEvents:1<<6];
    [partyBGroup.xmBtn addTarget:self action:@selector(retakePhoto:) forControlEvents:1<<6];
    [partyBGroup.cphBtn addTarget:self action:@selector(retakePhoto:) forControlEvents:1<<6];
    [scroll addSubview:partyBGroup];
    
    //    sgdd = [[AccidentPlaceView alloc] initWithFrame:CGRectMake(10, partyBGroup.maxY+10, ScreenWidth-20, 70)];
    //    sgdd.contentView.x = sgdd.contentView.x - 20;
    //
    //    [scroll addSubview:sgdd];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(10, partyBGroup.maxY + 25, ScreenWidth - 20, 50);
    [btn setTitle:@"提交" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    [btn addTarget:self action:@selector(confirmBtnClicked) forControlEvents:1 << 6];
    btn.backgroundColor = HNBlue;
    btn.layer.cornerRadius = 5;
    [scroll addSubview:btn];
    
    //高速交警
    //    if ([GlobleInstance.nationid isEqualToString:@"1"]) {
    //
    //        sgdd.hidden = false;
    //        btn.frame = CGRectMake(10, sgdd.maxY + 25, ScreenWidth - 20, 50);
    //    }
    //
    //    else {
    //        sgdd.hidden = true;
    //        btn.frame = CGRectMake(10, partyBGroup.maxY + 25, ScreenWidth - 20, 50);
    //    }
    
    scroll.contentSize = CGSizeMake(ScreenWidth, btn.maxY + 25);
    
    [self getCasehaplace];
    
    [self ocrAutofill];
}


-(void)selectTime
{
    NSMutableString *tmp = [NSMutableString stringWithFormat:@"%@",sgsj.contentField.text];
    NSString *maxDateStr = [tmp substringToIndex:tmp.length-3];
    NSDate *maxDate = [NSDate date:maxDateStr WithFormat:@"yyyy-MM-dd HH:mm"];
    
    WSDatePickerView *datePicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDayHourMinute currentDate:maxDate CompleteBlock:^(NSDate *startDate) {
        NSString *date = [startDate stringWithFormat:@"yyyy-MM-dd HH:mm:00"];
        NSLog(@"时间： %@",date);
        
        sgsj.contentField.text = date;
        
    }];
    
    datePicker.maxLimitDate = maxDate;
    
    datePicker.doneButtonColor = [UIColor orangeColor];//确定按钮的颜色
    
    [datePicker show];
}

#pragma mark - 重新拍照识别
-(void)retakePhoto:(UIButton *)btn
{
    DJCameraViewController *cameraVC = [DJCameraViewController new];
    if (btn == partyAGroup.xmBtn) {
        cameraVC.titleStr1 = @"甲方驾驶证照片";
        cameraVC.guideImageName = @"jsznf";
        cameraVC.index = 4;
    }
    
    if (btn == partyAGroup.cphBtn) {
        cameraVC.titleStr1 = @"甲方行驶证照片";
        cameraVC.guideImageName = @"xsznf";
        cameraVC.index = 5;
    }
    
    if (btn == partyBGroup.xmBtn) {
        cameraVC.titleStr1 = @"乙方驾驶证照片";
        cameraVC.guideImageName = @"jsznf";
        cameraVC.index = 6;
    }
    
    if (btn == partyBGroup.cphBtn) {
        cameraVC.titleStr1 = @"乙方行驶证照片";
        cameraVC.guideImageName = @"xsznf";
        cameraVC.index = 7;
    }
    
    cameraVC.isLandscape = YES;
    cameraVC.isShowWarnImage = YES;
    cameraVC.delegate = self;
    [self presentViewController:cameraVC animated:YES completion:nil];
}

#pragma mark - 相机代理
- (void)cameraViewController:(DJCameraViewController*)cameraVC ToObtainCameraPhotos:(UIImage*)image
{
    NSString* imageStr = [Util imageToString:image];
    
    NSNumber* type;
    if (cameraVC.index == 4) {
        type = @6;
    }
    if (cameraVC.index == 5) {
        type = @7;
    }
    if (cameraVC.index == 6) {
        type = @8;
    }
    if (cameraVC.index == 7) {
        type = @9;
    }
    
    NSMutableDictionary *bean = [NSMutableDictionary dictionary];
    
    NSString* userflag = [NSString stringWithFormat:@"%@", GlobleInstance.userflag];
    NSString* token = [NSString stringWithFormat:@"%@", GlobleInstance.token];
    [bean setValue:userflag forKey:@"userflag"];
    [bean setValue:token forKey:@"token"];
    [bean setObject:imageStr forKey:@"imageurl"];
    [bean setValue:type forKey:@"imagetype"];
    
    MBProgressHUD *imageHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    imageHud.label.text = @"正在识别，请稍候...";
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"hnjjappOCR" parameters:bean complete:^(id result, ResultType resultType) {
       
        [imageHud hideAnimated:YES];
        NSLog(@"hnjjappOCR ~ %@",result);
        if ([result[@"data"] isKindOfClass:[NSDictionary class]]) {
            if (cameraVC.index == 4) {
                GlobleInstance.jfocrname = result[@"data"][@"ocrname"];
                GlobleInstance.jfocrcardno = result[@"data"][@"ocrcardno"];
                partyAGroup.xmView.field.text = GlobleInstance.jfocrname;
                partyAGroup.jszView.field.text = GlobleInstance.jfocrcardno;
            }
            if (cameraVC.index == 5) {
                
                GlobleInstance.jfocrcarno = result[@"data"][@"ocrcarno"];
                GlobleInstance.jfocrvin = result[@"data"][@"ocrvin"];
                
                if (GlobleInstance.jfocrcarno.length == 7)
                {
                    NSString *jfRegion = [GlobleInstance.jfocrcarno substringWithRange:NSMakeRange(0, 1)];
                    NSString *jfCarNumber = [GlobleInstance.jfocrcarno substringFromIndex:1];
                    partyAGroup.selectList.contentLab.text = jfRegion;
                    partyAGroup.cphView.field.text = jfCarNumber;
                }
                
                partyAGroup.cjhView.field.text = GlobleInstance.jfocrvin;
            }
            if (cameraVC.index == 6) {
                GlobleInstance.yfocrname = result[@"data"][@"ocrname"];
                GlobleInstance.yfocrcardno = result[@"data"][@"ocrcardno"];
                partyBGroup.xmView.field.text = GlobleInstance.yfocrname;
                partyBGroup.jszView.field.text = GlobleInstance.yfocrcardno;
            }
            if (cameraVC.index == 7) {
                GlobleInstance.yfocrcarno = result[@"data"][@"ocrcarno"];
                GlobleInstance.yfocrvin = result[@"data"][@"ocrvin"];
                
                if (GlobleInstance.yfocrcarno.length == 7)
                {
                    NSString *yfRegion = [GlobleInstance.yfocrcarno substringWithRange:NSMakeRange(0, 1)];
                    NSString *yfCarNumber = [GlobleInstance.yfocrcarno substringFromIndex:1];
                    partyBGroup.selectList.contentLab.text = yfRegion;
                    partyBGroup.cphView.field.text = yfCarNumber;
                }
                
                partyBGroup.cjhView.field.text = GlobleInstance.yfocrvin;

            }
        }
        
    }];
}

#pragma mark - 获取事故地点和时间
-(void)getCasehaplace
{
    NSMutableDictionary *placeBean = [NSMutableDictionary dictionary];
    [placeBean setValue:GlobleInstance.userflag forKey:@"userflag"];
    [placeBean setValue:GlobleInstance.token forKey:@"token"];
    [placeBean setValue:GlobleInstance.appcaseno forKey:@"appcaseno"];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"jjappgetplace" parameters:placeBean complete:^(id result, ResultType resultType) {
        
        [hud hideAnimated:YES];
        NSLog(@"jjappgetplace ~ %@",result);
        
        if ([result[@"restate"] isEqualToString:@"1"])
        {
            if ([result[@"data"] isEqualToString:@""]) {
                //如果没有获取到定位地址，说明不是从历史进入 直接取
                sgdd.contentView.text = GlobleInstance.imageaddress;
            }
            
            else {
                sgdd.contentView.text = result[@"data"];
            }
            
        }
        
    }];
    
}

#pragma mark - 获取保单号
- (void)getBdhCode:(UIButton *)btn
{
    //取值
    jfcarno = [NSString stringWithFormat:@"%@%@", partyAGroup.selectList.contentLab.text, partyAGroup.cphView.field.text];
    jfframeno = partyAGroup.cjhView.field.text;
    yfcarno = [NSString stringWithFormat:@"%@%@", partyBGroup.selectList.contentLab.text, partyBGroup.cphView.field.text];
    yfframeno = partyBGroup.cjhView.field.text;
    
    if (btn == partyAGroup.codeBtn)
    {
        if (!([Util cheackLicense:jfcarno] || [Util checkLearnLicense:jfcarno]))
        {
            SHOWALERT(@"请填写正确的甲方车牌号");
            return;
        }
        
        if (partyAGroup.isLinPai || ![jfcarno hasPrefix:@"豫"]) {
            if (![Util checkChaimsNO:partyAGroup.cjhView.field.text])
            {
                SHOWALERT(@"请填写正确的车架号");
                return;
            }
        }
    }
    
    else
    {
        if (!([Util cheackLicense:yfcarno] || [Util checkLearnLicense:yfcarno]))
        {
            SHOWALERT(@"请填写正确的乙方车牌号");
            return;
        }
        
        if (partyBGroup.isLinPai || ![yfcarno hasPrefix:@"豫"])
        {
            if (![Util checkChaimsNO:yfframeno])
            {
                SHOWALERT(@"请填写正确的乙方车架号");
                return;
            }
        }
        
    }
    
    NSMutableDictionary *bdhBean = [NSMutableDictionary dictionary];
    
    [bdhBean setValue:GlobleInstance.userflag forKey:@"userflag"];
    [bdhBean setValue:GlobleInstance.appcaseno forKey:@"appcaseno"];
    [bdhBean setValue:GlobleInstance.token forKey:@"token"];
    [bdhBean setValue:@"" forKey:@"policyno"];
    
    if (btn == partyAGroup.codeBtn)
    {
        [bdhBean setValue:jfcarno forKey:@"casecarno"];
        
        NSString *tmpStr = [jfframeno uppercaseString];
        tmpStr = [tmpStr stringByReplacingOccurrencesOfString:@" " withString:@""];
        
        [bdhBean setValue:tmpStr forKey:@"frameno"];
    }
    
    else
    {
        [bdhBean setValue:yfcarno forKey:@"casecarno"];
        
        NSString *tmpStr = [yfframeno uppercaseString];
        tmpStr = [tmpStr stringByReplacingOccurrencesOfString:@" " withString:@""];
        
        [bdhBean setValue:tmpStr forKey:@"frameno"];
    }
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"jjappkckpSearchCpsNum" parameters:bdhBean complete:^(id result, ResultType resultType) {
        
        [hud hideAnimated:true];
        
        //      NSLog(@"获取保单号 -> %@", result);
        
        if ([result[@"restate"] isEqualToString:@"1"])
        {
            if (btn == partyAGroup.codeBtn)
            {
                partyAGroup.bdhView.field.text = result[@"data"][@"trafficinsno"];
            }
            
            else
            {
                partyBGroup.bdhView.field.text = result[@"data"][@"trafficinsno"];
            }
        }
        
        else
        {
            MBProgressHUD *tHud = [MBProgressHUD showHUDAddedTo:self.view animated:NO];
            tHud.mode = MBProgressHUDModeText;
            tHud.label.text = @"未查询到保单号，请手动输入";
            [tHud hideAnimated:NO afterDelay:1.5];
        }
        
    }];
}

- (void)ocrAutofill
{
    
    NSMutableDictionary *ocrBean = [NSMutableDictionary dictionary];
    [ocrBean setValue:GlobleInstance.userflag forKey:@"userflag"];
    [ocrBean setValue:GlobleInstance.token forKey:@"token"];
    [ocrBean setValue:GlobleInstance.appcaseno forKey:@"appcaseno"];
    
    MBProgressHUD *ocrHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"jjappgetOCRdata" parameters:ocrBean complete:^(id result, ResultType resultType) {
        
        [ocrHud hideAnimated:YES];
        NSLog(@"jjappgetOCRdata ~ %@",result);
        
        if (result) {
            if (result[@"casehaptime"]) {
                sgsj.contentField.text = result[@"casehaptime"];
            }
        }
        
        if ([result[@"data"] isKindOfClass:[NSArray class]]) {
            
            for (NSDictionary *dic in result[@"data"]) {
                //甲方驾驶证
                if ([dic[@"imagetype"] isEqual:@"6"])
                {
                    GlobleInstance.jfocrname = dic[@"ocrname"];
                    GlobleInstance.jfocrcardno = dic[@"ocrcardno"];
                }
                //甲方行驶证
                if ([dic[@"imagetype"] isEqual:@"7"])
                {
                    GlobleInstance.jfocrcarno = dic[@"ocrcarno"];
                    GlobleInstance.jfocrvin = dic[@"ocrvin"];
                    GlobleInstance.jfocrcartype = dic[@"ocrcartype"];
                }
                //乙方驾驶证
                if ([dic[@"imagetype"] isEqual:@"8"]) {
                    GlobleInstance.yfocrname = dic[@"ocrname"];
                    GlobleInstance.yfocrcardno = dic[@"ocrcardno"];
                }
                //乙方行驶证
                if ([dic[@"imagetype"] isEqual:@"9"]) {
                    GlobleInstance.yfocrcarno = dic[@"ocrcarno"];
                    GlobleInstance.yfocrvin = dic[@"ocrvin"];
                    GlobleInstance.yfocrcartype = dic[@"ocrcartype"];
                }
            }
        }
        
        /**********************************************/
        
        //填充甲方
        if ([GlobleInstance.jfocrcartype hasPrefix:@"小型"])
        {
            partyAGroup.radio1.checked = YES;
        }
        else
        {
            partyAGroup.radio2.checked = YES;
        }
        partyAGroup.xmView.field.text = GlobleInstance.jfocrname;
        if (GlobleInstance.jfocrcarno.length == 7)
        {
            NSString *jfRegion = [GlobleInstance.jfocrcarno substringWithRange:NSMakeRange(0, 1)];
            NSString *jfCarNumber = [GlobleInstance.jfocrcarno substringFromIndex:1];
            
            if ([partyAGroup.selectList.dataArray containsObject:jfRegion]) {
                partyAGroup.selectList.contentLab.text = jfRegion;
            }
            
            partyAGroup.cphView.field.text = jfCarNumber;
        }
        partyAGroup.jszView.field.text = GlobleInstance.jfocrcardno;
        partyAGroup.cjhView.field.text = GlobleInstance.jfocrvin;
        
        //填充乙方
        if ([GlobleInstance.yfocrcartype hasPrefix:@"小型"])
        {
            partyBGroup.radio1.checked = YES;
        }
        else
        {
            partyBGroup.radio2.checked = YES;
        }
        partyBGroup.xmView.field.text = GlobleInstance.yfocrname;
        if (GlobleInstance.yfocrcarno.length == 7)
        {
            NSString *yfRegion = [GlobleInstance.yfocrcarno substringWithRange:NSMakeRange(0, 1)];
            NSString *yfCarNumber = [GlobleInstance.yfocrcarno substringFromIndex:1];
            
            if ([partyBGroup.selectList.dataArray containsObject:yfRegion]) {
                partyBGroup.selectList.contentLab.text = yfRegion;
            }
            
            partyBGroup.cphView.field.text = yfCarNumber;
        }
        partyBGroup.jszView.field.text = GlobleInstance.yfocrcardno;
        partyBGroup.cjhView.field.text = GlobleInstance.yfocrvin;
        
    }];
    
}

#pragma mark - UITextField Delegate
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    //甲方车牌号
    if (textField == partyAGroup.cphView.field)
    {
        textField.text = [textField.text uppercaseString];
    }
    //甲方车架号
    if (textField == partyAGroup.cjhView.field)
    {
        textField.text = [textField.text uppercaseString];
    }
    //甲方驾驶证号
    if (textField == partyAGroup.jszView.field)
    {
        textField.text = [textField.text uppercaseString];
    }
    
    //乙方车牌号
    if (textField == partyBGroup.cphView.field)
    {
        textField.text = [textField.text uppercaseString];
    }
    //乙方车架号
    if (textField == partyBGroup.cjhView.field)
    {
        textField.text = [textField.text uppercaseString];
        
    }
    //乙方驾驶证号
    if (textField == partyBGroup.jszView.field)
    {
        textField.text = [textField.text uppercaseString];
    }
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if ([string isEqualToString:@""]) {
        return YES;
    }
    
    char commitChar = [string characterAtIndex:0];
    
    if (commitChar>96 && commitChar<123) {
        //小写变成大写
        NSString * uppercaseString = string.uppercaseString;
        
        NSString * str1 = [textField.text substringToIndex:range.location];
        
        NSString * str2 = [textField.text substringFromIndex:range.location];
        
        textField.text = [NSString stringWithFormat:@"%@%@%@",str1,uppercaseString,str2];
        
        return NO;
    }
    return YES;
}

//-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
//{
//    //甲方车牌号
//    if (textField == partyAGroup.cphView.field)
//    {
//        textField.text = [textField.text uppercaseString];
//        
//    }
//    //甲方车架号
//    if (textField == partyAGroup.cjhView.field)
//    {
//        textField.text = [textField.text uppercaseString];
//    }
//    //甲方驾驶证号
//    if (textField == partyAGroup.jszView.field)
//    {
//        textField.text = [textField.text uppercaseString];
//    }
//    
//    //乙方车牌号
//    if (textField == partyBGroup.cphView.field)
//    {
//        textField.text = [textField.text uppercaseString];
//    }
//    //乙方车架号
//    if (textField == partyBGroup.cjhView.field)
//    {
//        textField.text = [textField.text uppercaseString];
//        
//    }
//    //乙方驾驶证号
//    if (textField == partyBGroup.jszView.field)
//    {
//        textField.text = [textField.text uppercaseString];
//    }
//    return YES;
//}


#pragma mark - 提交按钮点击事件
- (void)confirmBtnClicked
{
    
    //取值
    jfcarno = [NSString stringWithFormat:@"%@%@", partyAGroup.selectList.contentLab.text, partyAGroup.cphView.field.text];
    yfcarno = [NSString stringWithFormat:@"%@%@", partyBGroup.selectList.contentLab.text, partyBGroup.cphView.field.text];
    jfcarType = partyAGroup.selectedIndex;
    jfname = partyAGroup.xmView.field.text;
    jfphoneNum = partyAGroup.lxdhView.field.text;
    jfdriveNum = partyAGroup.jszView.field.text;
    jfframeno = partyAGroup.cjhView.field.text;
    jfbdhNum = partyAGroup.bdhView.field.text;
    
    yfcarType = partyBGroup.selectedIndex;
    yfname = partyBGroup.xmView.field.text;
    yfphoneNum = partyBGroup.lxdhView.field.text;
    yfdriveNum = partyBGroup.jszView.field.text;
    yfframeno = partyBGroup.cjhView.field.text;
    yfbdhNum = partyBGroup.bdhView.field.text;
    
    //甲方判断
    if (!jfcarType)
    {
        SHOWALERT(@"请选择甲方车型");
        return;
    }
    
    if (jfname.length < 1)
    {
        SHOWALERT(@"请填写甲方姓名");
        return;
    }
    
    if (!([Util cheackLicense:jfcarno] || [Util checkLearnLicense:jfcarno]))
    {
        SHOWALERT(@"请填写正确的甲方车牌号");
        return;
    }
    
    if (![Util isMobileNumber:jfphoneNum])
    {
        SHOWALERT(@"请填写正确的甲方联系电话");
        return;
    }
    
    if (![IDyz validateIDCardNumber:jfdriveNum])
    {
        SHOWALERT(@"请填写正确的甲方驾驶证号");
        return;
    }
    
    if (partyAGroup.isLinPai || ![jfcarno hasPrefix:@"豫"]) {
        if (![Util checkChaimsNO:jfframeno])
        {
            SHOWALERT(@"请填写正确的甲方车架号");
            return;
        }
    }
    else {
        if (jfframeno.length < 1) {
            SHOWALERT(@"请填写甲方车架号");
            return;
        }
    }
    
    //乙方判断
    if (!yfcarType)
    {
        SHOWALERT(@"请选择乙方车型");
        return;
    }
    
    if (yfname.length < 1)
    {
        SHOWALERT(@"请填写乙方姓名");
        return;
    }
    
    if (!([Util cheackLicense:yfcarno] || [Util checkLearnLicense:yfcarno]))
    {
        SHOWALERT(@"请填写正确的乙方车牌号");
        return;
    }
    
    
    if (![Util isMobileNumber:yfphoneNum])
    {
        SHOWALERT(@"请填写正确的乙方联系电话");
        return;
    }
    
    if (![IDyz validateIDCardNumber:yfdriveNum])
    {
        SHOWALERT(@"请填写正确的乙方驾驶证号");
        return;
    }
    
    if (partyBGroup.isLinPai || ![yfcarno hasPrefix:@"豫"])
    {
        if (![Util checkChaimsNO:yfframeno])
        {
            SHOWALERT(@"请填写正确的乙方车架号");
            return;
        }
    }
    else {
        if (yfframeno.length < 1) {
            SHOWALERT(@"请填写乙方车架号");
            return;
        }
    }
    
    //双方是否相同判断
    if ([jfcarno isEqualToString:yfcarno])
    {
        SHOWALERT(@"甲乙双方车牌号不能相同");
        return;
    }
    
    if ([jfphoneNum isEqualToString:yfphoneNum])
    {
        SHOWALERT(@"甲乙双方手机号不能相同");
        return;
    }
    
    if ([jfdriveNum isEqualToString:yfdriveNum])
    {
        SHOWALERT(@"甲乙双方驾驶证号不能相同");
        return;
    }
    
    if ([jfframeno isEqualToString:yfframeno])
    {
        SHOWALERT(@"甲乙双方车架号不能相同");
        return;
    }
    
    if ([jfbdhNum isEqualToString:yfbdhNum])
    {
        if (jfbdhNum.length > 1 && yfbdhNum.length > 1)
        {
            SHOWALERT(@"甲乙双方保单号不能相同");
            return;
        }
    }
    
    //有临牌或者省外车辆
    if (partyAGroup.isLinPai || partyBGroup.isLinPai || ![jfcarno hasPrefix:@"豫"] || ![yfcarno hasPrefix:@"豫"]) {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请人工核实外省或临牌车辆的证件信息真伪" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"认可提交"style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            [self uploadCaseInfo];
            
        }];
        [alertController addAction:okAction];
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"人工核实"style:UIAlertActionStyleDefault handler:nil];
        [alertController addAction:cancelAction];
        
        [self presentViewController:alertController animated:YES completion:nil];
    }
    
    //河南非临牌
    else {
        [self uploadCaseInfo];
    }
    
}

-(void)uploadCaseInfo
{
    NSMutableDictionary *bean = [NSMutableDictionary dictionary];
    
    NSArray *arr = @[@{@"carownname":jfname,
                       @"carownphone":jfphoneNum,
                       @"casecarno":jfcarno,
                       @"cartype":jfcarType,
                       @"frameno":jfframeno,
                       @"cardno":jfdriveNum,
                       @"driverlicence":jfdriveNum,
                       @"party":@"1",
                       @"temporary":[NSString stringWithFormat:@"%d",partyAGroup.isLinPai]},
                     @{@"carownname":yfname,
                       @"carownphone":yfphoneNum,
                       @"casecarno":yfcarno,
                       @"cartype":yfcarType,
                       @"frameno":yfframeno,
                       @"cardno":yfdriveNum,
                       @"driverlicence":yfdriveNum,
                       @"party":@"0",
                       @"temporary":[NSString stringWithFormat:@"%d",partyBGroup.isLinPai]}];
    
    NSString *appcaseno = GlobleInstance.appcaseno;
    
    [bean setValue:arr forKey:@"casecarlist"];
    [bean setValue:appcaseno forKey:@"appcaseno"];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"jjappcheckcbxx" parameters:bean complete:^(id result, ResultType resultType) {
        
        [hud hideAnimated:YES];
        
        if (result) {
            NSLog(@"承保信息 ~ %@",[Util objectToJson:result]);
        }
        
        if ([result[@"restate"] isEqualToString:@"1"]) {
            
           
            
            ZRRDViewController *vc = [ZRRDViewController new];
            
            InfoModel *jfModel = [InfoModel new];
            jfModel.carType = jfcarType;
            jfModel.name = jfname;
            jfModel.carNum = jfcarno;
            jfModel.phoneNum = jfphoneNum;
            jfModel.driveNum = jfdriveNum;
            jfModel.vinNum = jfframeno;
            jfModel.bdhNum = jfbdhNum;
            
            InfoModel *yfModel = [InfoModel new];
            yfModel.carType = yfcarType;
            yfModel.name = yfname;
            yfModel.carNum = yfcarno;
            yfModel.phoneNum = yfphoneNum;
            yfModel.driveNum = yfdriveNum;
            yfModel.vinNum = yfframeno;
            yfModel.bdhNum = yfbdhNum;
            
            vc.jfModel = jfModel;
            vc.yfModel = yfModel;
            vc.selectedItem = _selectedItem;
            vc.caseDes = _caseDes;
            vc.accidentplace = sgdd.contentView.text;
            vc.casehaptime = sgsj.contentField.text;
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        else {
            SHOWALERT(result[@"redes"]);
        }
        
    }];
    
}

@end
